module.exports = function ($scope, $resource, $modalInstance, toaster, obj, update) {

    var url = '';
    init();
    function init(){
        $scope.update = update;
        $scope.fromDate = {
            'max_price': 0,
            'order_fee': 0,
            'order_service_charge_type': '2',
            'back_servicefee': '0'
        }
        if(update){
            url = '/api/ac/pc/payBmAccountService/updateServiceCharge';
            $scope.fromDate.company_name = obj.company_name;
            $scope.fromDate.company_code = obj.company_code;
            $scope.fromDate.max_price = (obj.max_price||0) * 0.01;
            $scope.fromDate.order_fee = (obj.order_fee||0) * 0.01;
            $scope.fromDate.order_service_charge_type = obj.order_service_charge_type;
            $scope.fromDate.back_servicefee = obj.back_servicefee;
        } else {
            url = '/api/ac/pc/payBmAccountService/addServiceCharge';
        }
    }

    $scope.ok = function(){
        if(!update && !$scope.fromDate.company_code){
            toaster.warning({title: '', body: '请输入商户编号'});
            return;
        }

        $resource(url, {}, {}).save($scope.fromDate, function(res){
			if(res.errcode === 0){
                $modalInstance.close($scope.fromDate);
			} else {
				toaster.error({title: '', body: res.errmsg});
			}
		});
    }


    $scope.cancel = function () {
        $modalInstance.dismiss('cancel');
    }


};